import router from "@/router";
import Cookies from "js-cookie";
import { post } from "@/utils/http.js"; //引入封装工具

export default {
  state: {
    AddData: "",
    admins: {},
  },

  mutations: {
    add(state, adds) {
      state.AddData = adds;
    },

    // 退出
    outs() {
      // 退出接口
      let data = {
        _gp: "admin", //请求参数
        _mt: "logout", //请求参数
      };
      // axios.post("http://192.168.1.188:8080/m.api", data)
      post(data).then((res) => {
        sessionStorage.removeItem("token");
        Cookies.remove("token");
        router.push("/Login");
      });
    },
    //保存账号
    adds(admins, v) {
      console.log(v, 999);
      admins.admins = v;
      console.log(admins, 888);
    },
  },
  actions: {
    add(context, adds) {
      context.commit("add", adds);
    },

    outs(context) {
      context.commit("outs"); //操作mutations里面的
    },
    adds({ commit }, v) {
      console.log(v);
      commit("adds", v);
    },
  },
};
